package Controle;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.ClienteDAO2;

import modelo.Cliente;

@WebServlet("/ClienteServlet")
public class ClienteServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	private ClienteDAO2 dao = new ClienteDAO2();
       
    public ClienteServlet() {
    	super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		Cliente cliente = new Cliente(new Integer(request.getParameter("codigo")),
									  request.getParameter("nome"),
									  request.getParameter("tipoPessoa"),
									  request.getParameter("cpf"),
									  request.getParameter("endereco"),
									  request.getParameter("telefone"));
		
		dao.incluir(cliente);
		
		response.sendRedirect("/Clientes/incluirCliente.jsf");
	}

}
